<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<body>
	<fieldset class="layui-elem-field layui-field-title site-title">
		<legend>
			<a name="fixbar" style="font-size: 16px; color: #ce2424;">考勤管理</a>
		</legend>
	</fieldset>
	<form class="layui-form" id="myForm" method="post" lay-filter="stuform">
		<div class="layui-form-item">
			<div class="layui-inline" style="width: 420px;">
				<label class="layui-form-label">班级名称：</label>
				<div class="layui-input-block">
					<select id="bjid" lay-filter="bjselect" lay-verify="required"
						lay-search>
						<c:forEach var="d" items="${bjs}">
							<option value="${d.id}">${d.name}</option>
						</c:forEach>
					</select>
				</div>
			</div>
			<div class="layui-inline" style="width: 420px;">
				<label class="layui-form-label">学员姓名：</label>
				<div class="layui-input-block">
					<select id="student" lay-filter="stuselect" lay-search>
						<option value=""></option>
						<c:forEach var="s" items="${stu}">
							<option value="${s.id}">${s.name}</option>
						</c:forEach>
					</select>
				</div>
			</div>
		</div>
	</form>
	<script type="text/html" id="barDemo">
	<div class="layui-btn-container">
		<button class="layui-btn layui-btn-sm" lay-event="xiug">修改</button>
  	</div>
</script>
	<table id="checkingin" lay-filter="checkingin"></table>
	<script type="text/javascript">
		layui.use('form', function() {
			var form = layui.form;
			form.render('select');
			
			form.on('select(stuselect)', function(data) {
				var suuid = data.value;
				var bjuuid = $("#bjid").val();
				layui.use('table', function() {
					var table = layui.table;
					table.reload('idTest', {
						url : 'checkingin/page',
						where : {
							bjuuid : bjuuid,
							suuid:suuid
						},
						page : {
							curr : 1
						//重新从第 1 页开始
						}
					});
				});
			});
			
			form.on('select(bjselect)', function(data) {
				var bjuuid = data.value;
				$("#student").empty();
				var id = $(this).attr("lay-value");
				$.ajax({
					type : "POST",
					data : {
						id : id
					},
					url : "checkingin/select",
					success : function(data) {
						var form = layui.form;
						var json = data;
						$("#student").append('<option value=""></option>');
						for (var i = 0; i < data.length; i++) {
							var json = data[i];
							var str = "";
							str += '<option value="'+json.id+'">' + json.name
									+ '</option>';
							$("#student").append(str);
						}
							form.render('select');
					}
				});
				layui.use('table', function() {
					var table = layui.table;
					table.reload('idTest', {
						url : 'checkingin/page',
						where : {
							bjuuid : bjuuid,
							suuid:""
						},
						page : {
							curr : 1
						//重新从第 1 页开始
						}
					});
				});
			});
		});
		layui.use('table', function() {
			var bjuuid = $("#bjid").val();
			var table = layui.table;
			table.render({
				elem : '#checkingin',
				url : 'checkingin/page',
				title : "学员考核",
				id : 'idTest',
				where:{bjuuid : bjuuid},
				cols : [ [ {
					field : 'curriculumName',
					title : '课程'
				}, {
					field : 'banji',
					title : '班级'
				}, {
					field : 'studentName',
					title : '学生'
				}, {
					field : 'time',
					title : '时间'
				}, {
					field : 'isReach',
					title : '签到情况'
				}, {
					fixed : 'right',
					title : '功能',
					align : 'center',
					toolbar : '#barDemo',
				} ] ],
				page : true
			});
			
			table.on('tool(checkingin)', function(obj) {
				var data = obj.data;
				var id = data.id;
				if (obj.event === "xiug") {
				 $("#content").load("${pageContext.request.contextPath }/checkingin/edit", {id:id})
				}
			});
		});
	</script>
</body>
</html>